package com.yh.csx.bsf.flow.dao.dal;

import com.yh.csx.bsf.core.base.Ref;
import com.yh.csx.bsf.core.util.StringUtils;
import com.yh.csx.bsf.flow.core.db.ConvertUtil;
import com.yh.csx.bsf.flow.core.db.DbConn;
import com.yh.csx.bsf.flow.dao.dal.auto.t_flow_log_base_dal;
import com.yh.csx.bsf.flow.dao.model.auto.t_flow_log_model;
import com.yh.csx.bsf.flow.dao.model.auto.t_model_model;
import lombok.val;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/** 代码自动生成工具自动生成,不要在这里写自己的代码，否则会被自动覆盖哦 - 车毅*/
public class t_flow_log_dal extends t_flow_log_base_dal
{
    public List<t_flow_log_model> getPage(DbConn db, String flow_title, Integer flow_id, String log, Integer type, Integer pageIndex, Integer pageSize, Ref<Integer> totalSize){
        val par = new ArrayList<>();
        val rs = new ArrayList<t_flow_log_model>();

        StringBuilder sb = new StringBuilder(" from t_flow_log where 1=1 ");
        if(!StringUtils.isEmpty(flow_title)){
            par.add(flow_title);
            sb.append(" and flow_title like concat('%', ?, '%')");
        }
        if(flow_id!=null&& flow_id>0){
            par.add(flow_id);
            sb.append(" and flow_id=?");
        }
        if(!StringUtils.isEmpty(log)){
            par.add(log);
            sb.append(" and log like concat('%', ?, '%')");
        }
        if(type!=null&&type>=0){
            par.add(type);
            sb.append(" and type=?");
        }
        String sql = "select * "+sb.toString()+" order by id desc "+String.format(" limit %s,%s",(pageIndex-1)*pageSize,pageSize);
        String countSql = "select count(0) "+sb.toString();
        val ds = db.executeList(sql, par.toArray());
        if (ds != null && ds.size() > 0)
        {
            for (Map<String,Object> dr : ds)
            {
                rs.add(createModel(dr));
            }
        }
        totalSize.setData(ConvertUtil.objToInt(db.executeScalar(countSql,par.toArray())));
        return rs;
    }
}
